﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace CP.DataAccess
{
    public class MasterDAL
    {
        SqlConnection cnx;

        public MasterDAL()
        {
            cnx = new SqlConnection();
            cnx.ConnectionString = ConfigurationManager.ConnectionStrings["cnx"].ConnectionString;
        }

        public SqlCommand CreateCommand(string procedimiento)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = procedimiento;
            command.CommandType = CommandType.StoredProcedure;
            command.Connection = cnx;

            return command;
        }

        public SqlDataReader ExecuteReader(SqlCommand command)
        {
            cnx.Open();
            return command.ExecuteReader(CommandBehavior.CloseConnection);
        }

        public void AddInParameter(SqlCommand command, string paramName, object value)
        {
            command.Parameters.AddWithValue(paramName, value); 
        }

        public void ExecuteNonQuery(SqlCommand command)
        {
            cnx.Open();
            command.ExecuteNonQuery();
            cnx.Close();
        }
    }
}
